package cn.fl.spdealer.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.fl.capital.constant.CapPrjArInfoConstant;
import cn.fl.capital.transform.CapPrjArInfoVOTransform;
import cn.fl.capital.vo.CapPrjArInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.kgs.utils.AuthenticationUtils;
import cn.fl.kgs.utils.DES;
import cn.fl.product.service.ISplCapPrjArInfoService;
import fl.mongo.facade.capital.dto.CapPriArInfoDTO;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.service.ICacheService;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.store.api.ISplRelOpLogApiService;
import fl.spl.facade.store.condition.SplRelOpLogQC;
import fl.spl.facade.store.dto.SplRelOpLogDTO;

@Controller
@RequestMapping("/splGroup/relation")
public class SplGroupRelationController extends BaseController{
	private static final Logger logger = LoggerFactory.getLogger(SplGroupRelationController.class);
	@Autowired
	private ISplRelOpLogApiService splRelOpLogApiService ;
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService ;
	
	@Autowired
	private ICacheService cacheService ;

	@Autowired
	private ISplCapPrjArInfoService splCapPrjArInfoService ;
	 /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object toListPage(HttpServletRequest request, HttpServletResponse response) {
    	ModelAndView view = new ModelAndView("/spdealer/splGroup/splGroupRelationList");
    	Long usrId = CurrentThreadContext.getCurrentUserId();
    	String cachestr="kgs:kgshtml:%#@"+usrId+"$!^:(#search";
        //在缓存里获取
        String token =(String) this.cacheService.get(cachestr, "remote");
        if(null==token || "".equals(token)){
            token = AuthenticationUtils.reqAuthenticationByappId();//获取token
            //BaseLogUtils.info(logger, "getToken", "加载token到searchJsp页面.", CurrentThreadContext.getCurrentUserName());
            this.cacheService.add(cachestr,token,"remote",1800);
        }

        view.addObject("token", DES.encrypt(token));//加密

		return view;
    }
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toRelationPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object toRelationPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("kgs/searchJsp");//加载前端的html 顺便把参数给前端
        //在缓存里获取
        String token = AuthenticationUtils.reqAuthenticationByappId();//获取token

        view.addObject("token", DES.encrypt(token));//加密
        view.addObject("usrId", CurrentThreadContext.getCurrentUserId());
        return view;
    }
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toMemberRelationPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object toMemberRelationPage(HttpServletRequest request, HttpServletResponse response) {
    	String id = request.getParameter("id");
    	ModelAndView view = new ModelAndView("/spdealer/splGroup/splMemberRelationPage");
    	Long usrId = CurrentThreadContext.getCurrentUserId();
    	String cachestr="kgs:kgshtml:%#@"+usrId+"$!^:(#search";
        //在缓存里获取
        String token =(String) this.cacheService.get(cachestr, "remote");
        if(null==token || "".equals(token)){
            token = AuthenticationUtils.reqAuthenticationByappId();//获取token
            //BaseLogUtils.info(logger, "getToken", "加载token到searchJsp页面.", CurrentThreadContext.getCurrentUserName());
            this.cacheService.add(cachestr,token,"remote",1800);
        }

        view.addObject("token", DES.encrypt(token));//加密

    	view.addObject("id", id);
    	return view;
    }
    
    @RequestMapping(value = "/toMemberRelationList.do", method = { RequestMethod.GET})
	public Object toMemberRelationList(HttpServletRequest request, HttpServletResponse response){
    	
    	String groupId = request.getParameter("groupId");
    	ModelAndView view = new ModelAndView("/spdealer/splGroup/splLnkMemberRelationPage");
    	List<SysDictionaryDTO> splOpTypCds = this.sysDictionaryApiService.searchGroupAll(SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD, fl.spl.facade.framework.constant.DictionaryConstant.SPL_OP_TYP_CD);
		List<KeyValueVO> opTypCd = null ;
		if(CollectionUtils.isNotEmpty(splOpTypCds)){
			opTypCd = new ArrayList<>(splOpTypCds.size());
			for(SysDictionaryDTO dto : splOpTypCds){
				if(BaseConstant.IS_YESNO_YES == dto.getIsSysDef()){
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(dto.getCode());
					keyValueVO.setValue(dto.getCodeNm());
					opTypCd.add(keyValueVO);
				}
			}
		}
		List<KeyValueVO> signDesc = this.sysDictionaryApiService.getKvList(fl.spl.facade.framework.constant.DictionaryConstant.SPL_SIGN_DESC_CD,SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
		
		
		view.addObject("signDesc", JSON.toJSON(signDesc));
		view.addObject("opTypCd", JSON.toJSON(opTypCd));
    	view.addObject("groupId", groupId);
    	return view ;
    }
	@RequestMapping(value = "/initMemberRelationList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initMemberRelationList(HttpServletRequest request, HttpServletResponse response){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"查询成功");
		StringBuffer url = new StringBuffer("http://10.20.7.110:8090/sq/group");
		String groupId = request.getParameter("groupId");
		String cname = request.getParameter("cname");
		String orgCode = request.getParameter("orgCode");
		String audStsCd = request.getParameter("audStsCd");
		String isBlackList = request.getParameter("isBlackList");
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pageSize");
		
		if(StringUtils.isEmpty(groupId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("集团ID为空，查询失败！");
			return result ;
		}
		url.append("/");
		url.append(groupId);
		url.append("?sign=1");
		if(StringUtils.isNotEmpty(cname)){
			url.append("&c_name="+cname);
		}
		if(StringUtils.isNotEmpty(orgCode)){
			url.append("&org_code="+orgCode);
		}
		if(StringUtils.isNotEmpty(isBlackList)){
			url.append("&IS_BLACK_LIST="+isBlackList);
		}
		if(StringUtils.isNotEmpty(audStsCd)){
			url.append("&AUD_STS_CD="+audStsCd);
		}
		if(StringUtils.isNotEmpty(currentPage)){
			url.append("&currentPage="+currentPage);
		}
		if(StringUtils.isNotEmpty(pageSize)){
			url.append("&pageSize="+pageSize);
		}else{
			url.append("&pageSize=100");
		}
		String dataResult = this.getResult(url.toString(),null);
		
		List<JSONObject> array = new ArrayList<>();
		int total = 0 ;
		if(StringUtils.isNotEmpty(dataResult)){
			List<Long> lnkCompIds = new ArrayList<>();
			List<Long> splIds = new ArrayList<>();
			JSONObject dataResultJSON = (JSONObject)JSONObject.parse(dataResult);
			String data = dataResultJSON.getString("data");
			JSONObject dataJSON = (JSONObject)JSONObject.parse(data);
			if(dataJSON.get("count") != null){
				total = Integer.valueOf(dataJSON.get("count").toString());
			}
			JSONArray list_company = (JSONArray)JSONArray.parse(dataJSON.getString("list_company"));
			for (Object object : list_company) {
				JSONObject json = (JSONObject)JSONObject.toJSON(object);
				Object lnkCompIdObj= json.get("LNK_COMP_ID");
				if(lnkCompIdObj != null){
					Long lnkCompId = Long.valueOf(lnkCompIdObj.toString());
					lnkCompIds.add(lnkCompId);
				}
				Object splIdObj = json.get("SPL_ID");
				if(splIdObj != null){
					Long splId = Long.valueOf(splIdObj.toString());
					splIds.add(splId);
				}
			}
			Map<Long, SplRelOpLogDTO> splToLogMap = new HashMap<>();
			Map<Long, SplRelOpLogDTO> lnkToLogMap = new HashMap<>();
			SplRelOpLogQC querySplRelLogQC = new SplRelOpLogQC();
			querySplRelLogQC.setDataIdList(splIds);
			querySplRelLogQC.setBizTypCd("SPL");
			List<SplRelOpLogDTO> splRelOpLog = splRelOpLogApiService.searchSplRelOpLogListByDataIdS(querySplRelLogQC );
			if(CollectionUtils.isNotEmpty(splRelOpLog)){
				for (SplRelOpLogDTO splRelOpLogDTO : splRelOpLog) {
					splToLogMap.put(splRelOpLogDTO.getDataId(), splRelOpLogDTO);
				}
			}
			SplRelOpLogQC queryLnkRelOpLogQC = new SplRelOpLogQC();
			queryLnkRelOpLogQC.setDataIdList(lnkCompIds);
			queryLnkRelOpLogQC.setBizTypCd("LNK");
			List<SplRelOpLogDTO> lnkRelOpLog = splRelOpLogApiService.searchSplRelOpLogListByDataIdS(queryLnkRelOpLogQC );
			if(CollectionUtils.isNotEmpty(lnkRelOpLog)){
				for (SplRelOpLogDTO splRelOpLogDTO : lnkRelOpLog) {
					lnkToLogMap.put(splRelOpLogDTO.getDataId(), splRelOpLogDTO);
				}
			}
			Map<String, String> signDescMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, "SPL0052");
			Map<String, String> opTypCdMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, "SPL0044");
			for (Object object : list_company) {
				JSONObject json = (JSONObject)JSONObject.toJSON(object);
				if(json.get("LNK_COMP_ID") != null){
					json.put("dataTypeCd", 2);
					SplRelOpLogDTO splRelOpLogDTO = lnkToLogMap.get(Long.valueOf(json.get("LNK_COMP_ID").toString()));
					if(splRelOpLogDTO  != null){
						json.put("signDesc", splRelOpLogDTO.getSignDesc());
						json.put("signDescNm", signDescMap.get(splRelOpLogDTO.getSignDesc()));
						json.put("opTypCd", splRelOpLogDTO.getOpTypCd());
						json.put("opTypCdNm", opTypCdMap.get(splRelOpLogDTO.getOpTypCd()));
					}
				}
				if(json.get("SPL_ID")!= null){
					json.put("dataTypeCd", 1);
					SplRelOpLogDTO splRelOpLogDTO = splToLogMap.get(Long.valueOf(json.get("SPL_ID").toString()));
					if(splRelOpLogDTO  != null){
						json.put("signDesc", splRelOpLogDTO.getSignDesc());
						json.put("signDescNm", signDescMap.get(splRelOpLogDTO.getSignDesc()));
						json.put("opTypCd", splRelOpLogDTO.getOpTypCd());
						json.put("opTypCdNm", opTypCdMap.get(splRelOpLogDTO.getOpTypCd()));
					}
				}
				array.add(json);
			}
			
		}
		return new ListPageVO<>(array,total);
	}
	
	private String getResult(String url,String token){
		 List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();  
		 String result="";
		 CloseableHttpClient httpClient = HttpClients.createDefault();
		 try{
			 String sign= DigestUtils.md5Hex(("GET" + url).getBytes("utf-8"));
		     url = url + "&sign=" + sign;
			 //HttpPost httpPost = new HttpPost(url);
			 HttpGet httpGet = new HttpGet(url);
			//配置超时时间
           RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();//设置请求和传输超时时间
           httpGet.setConfig(requestConfig);
           httpGet.setHeader("token", token);
           //请求体
           CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpGet);//执行请求
           //响应状态
           System.out.println("Post发送请求，请求时间戳=,响应状态："+closeableHttpResponse.getStatusLine());
           //获取响应对象
           HttpEntity resEntity = closeableHttpResponse.getEntity();
           if(resEntity!=null){
               result = EntityUtils.toString(resEntity, "UTF-8");
           }
           //销毁
           EntityUtils.consume(resEntity);
		 }catch (UnsupportedEncodingException e) {
	            System.out.println("POST发送失败,Error:"+e.getMessage());
			e.printStackTrace();
	        } catch (ClientProtocolException e) {
	            System.out.println("POST发送失败,Error:"+e.getMessage());
	            e.printStackTrace();
	        } catch (IOException e) {
	            String message = "POST发送请求URL:" + url + "Params:" + JSON.toJSONString(params) + "异常,Exception[" + e.getMessage() + "]";
	            System.out.println("POST发送失败,Error:"+message);
				e.printStackTrace();
	        }finally {
	            try {
	                httpClient.close();
	            } catch (IOException e) {
	            }
	        }
		return result;
	
   }
	
	@RequestMapping(value = "/initRelationList.do", method = { RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Object initRelationList(HttpServletRequest request, HttpServletResponse response){
		String name = request.getParameter("name");
		String id = request.getParameter("id");
		String currentPage = request.getParameter("currentPage");
		String pageSize = request.getParameter("pageSize");
		JSONObject obj = new JSONObject();
        
        
        
		if(StringUtils.isNotEmpty(name)){
			obj.put("name", name);
		}
		if(StringUtils.isNotEmpty(id)){
			obj.put("id", Long.valueOf(id));
		}
		if(StringUtils.isEmpty(currentPage)){
			currentPage = "1" ;
		}
		if(StringUtils.isEmpty(pageSize)){
			pageSize = "10";
		}
		obj.put("currentPage", Integer.valueOf(currentPage));
		obj.put("pageSize", Integer.valueOf(pageSize));
		
		Long usrId = CurrentThreadContext.getCurrentUserId();
    	String cachestr="kgs:kgshtml:%#@"+usrId+"$!^:(#search";
        //在缓存里获取
        String token =(String) this.cacheService.get(cachestr, "remote");
        if(null==token || "".equals(token)){
            token = AuthenticationUtils.reqAuthenticationByappId();//获取token
            //BaseLogUtils.info(logger, "getToken", "加载token到searchJsp页面.", CurrentThreadContext.getCurrentUserName());
            this.cacheService.add(cachestr,token,"remote",1800);
        }
        String url = "http://10.20.7.110:8090/sq/getGroupList" ;
        
        
		 List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();  
		 String result="";
		 CloseableHttpClient httpClient = HttpClients.createDefault();
		 HttpClient httpClient2 = new HttpClient();
		 try{
			  //String sign= DigestUtils.md5Hex(("POST" + url).getBytes("utf-8"));
			  //url = url + "&sign=" + sign;
			  HttpPost httpPost = new HttpPost(url);
			  //配置超时时间
			  RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();//设置请求和传输超时时间
			  httpPost.setConfig(requestConfig);
			  httpPost.setHeader("token", DES.encrypt(token));
			  httpPost.setHeader("content-Type", "application/json;charset=UTF-8");
			  StringEntity se = new StringEntity(obj.toJSONString());
			  se.setContentType("text/json");
			  httpPost.setEntity(se);
			  //请求体
			  CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);//执行请求
			  //响应状态
			  //System.out.println("Post发送请求，请求时间戳=,响应状态："+closeableHttpResponse.getStatusLine());
			  //获取响应对象
			  HttpEntity resEntity = closeableHttpResponse.getEntity();
			  if(resEntity!=null){
			      result = EntityUtils.toString(resEntity, "UTF-8");
			  }
			  //销毁
			  EntityUtils.consume(resEntity);
		 }catch (UnsupportedEncodingException e) {
	            System.out.println("POST发送失败,Error:"+e.getMessage());
			e.printStackTrace();
	        } catch (ClientProtocolException e) {
	            System.out.println("POST发送失败,Error:"+e.getMessage());
	            e.printStackTrace();
	        } catch (IOException e) {
	            String message = "POST发送请求URL:" + url + "Params:" + JSON.toJSONString(params) + "异常,Exception[" + e.getMessage() + "]";
	            System.out.println("POST发送失败,Error:"+message);
				e.printStackTrace();
	        }finally {
	            try {
	                httpClient.close();
	            } catch (IOException e) {
	            }
	        }
        if(StringUtils.isNotEmpty(result)){
        	JSONObject dataResultJSON = (JSONObject)JSONObject.parse(result);
        	return dataResultJSON ;
        }else{
        	JSONObject jsonObject = new JSONObject();
        	jsonObject.put("data", null);
        	return jsonObject ;
        }
	}
	
	@RequestMapping(value = "/getGroupBySplIdOrLnkId.do", method = { RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Object getGroupBySplIdOrLnkId(HttpServletRequest request, HttpServletResponse response){
		String splId = request.getParameter("splId");
		String lnkId = request.getParameter("lnkId");
		
		JSONObject obj = new JSONObject();
        
        if(StringUtils.isEmpty(lnkId) && StringUtils.isEmpty(splId)){
        	obj.put("data", new JSONObject());
        	return obj ;
        }
        StringBuffer sb = new StringBuffer("http://10.20.7.110:8090/sq/groupByComp");
		if(StringUtils.isNotEmpty(splId)){
			sb.append("?SPL_ID="+splId);
		}
		if(StringUtils.isNotEmpty(lnkId)){
			sb.append("?LNK_COMP_ID="+lnkId);
		}
		
		Long usrId = CurrentThreadContext.getCurrentUserId();
    	String cachestr="kgs:kgshtml:%#@"+usrId+"$!^:(#search";
        //在缓存里获取
        String token =(String) this.cacheService.get(cachestr, "remote");
        if(null==token || "".equals(token)){
            token = AuthenticationUtils.reqAuthenticationByappId();//获取token
            this.cacheService.add(cachestr,token,"remote",1800);
        }
        
		 List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();  
		 String result="";
		 CloseableHttpClient httpClient = HttpClients.createDefault();
		 HttpClient httpClient2 = new HttpClient();
		 try{
			  //String sign= DigestUtils.md5Hex(("POST" + url).getBytes("utf-8"));
			  //url = url + "&sign=" + sign;
			  //HttpPost httpPost = new HttpPost(url);
			  HttpGet httpGet = new HttpGet(sb.toString());
			  //配置超时时间
			  RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();//设置请求和传输超时时间
			  httpGet.setConfig(requestConfig);
			  httpGet.setHeader("token", DES.encrypt(token));
			  httpGet.setHeader("content-Type", "application/json;charset=UTF-8");
			  /*StringEntity se = new StringEntity(obj.toJSONString());
			  se.setContentType("text/json");
			  httpPost.setEntity(se);*/
			  //请求体
			  CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpGet);//执行请求
			  //获取响应对象
			  HttpEntity resEntity = closeableHttpResponse.getEntity();
			  if(resEntity!=null){
			      result = EntityUtils.toString(resEntity, "UTF-8");
			      BaseLogUtils.info(logger, "getGroupBySplIdOrLnkId", "查询集团成功："+JSON.toJSONString(result));
			  }
			  //销毁
			  EntityUtils.consume(resEntity);
		 }catch (UnsupportedEncodingException e) {
			e.printStackTrace();
	        } catch (ClientProtocolException e) {
	            e.printStackTrace();
	        } catch (IOException e) {
				e.printStackTrace();
	        }finally {
	            try {
	                httpClient.close();
	            } catch (IOException e) {
	            }
	        }
        if(StringUtils.isNotEmpty(result)){
        	JSONObject dataResultJSON = (JSONObject)JSONObject.parse(result);
        	return dataResultJSON ;
        }else{
        	JSONObject jsonObject = new JSONObject();
        	jsonObject.put("data", new JSONObject());
        	return jsonObject ;
        }
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/showCapPrj.do", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object showCapPrj(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("/spdealer/capPrjAr/GroupCapArInfo");
		view.addObject("dataId", id);
		return view;
	}
	@RequestMapping(value = "/getCapPrjArInfo.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getCapPrjArInfo(HttpServletRequest request, HttpServletResponse response){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"查询成功");
		StringBuffer url = new StringBuffer("http://10.20.7.110:8090/sq/group");
		String groupId = request.getParameter("dataId");
		if(StringUtils.isEmpty(groupId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("集团ID为空，查询失败！");
			return result ;
		}
		url.append("/");
		url.append(groupId);
		String dataResult = this.getResult(url.toString(),null);

		List<JSONObject> array = new ArrayList<>();
		int total = 0 ;
		if(StringUtils.isNotEmpty(dataResult)) {
			List<Long> lnkCompIds = new ArrayList<>();
			List<Long> splIds = new ArrayList<>();
			List<Long> cstIds = new ArrayList<>();
			JSONObject dataResultJSON = (JSONObject) JSONObject.parse(dataResult);
			String data = dataResultJSON.getString("data");
			JSONObject dataJSON = (JSONObject) JSONObject.parse(data);
			if (dataJSON.get("count") != null) {
				total = Integer.valueOf(dataJSON.get("count").toString());
			}
			JSONArray list_company = (JSONArray) JSONArray.parse(dataJSON.getString("list_company"));
			for (Object object : list_company) {
				JSONObject json = (JSONObject) JSONObject.toJSON(object);
				Object lnkCompIdObj = json.get("LNK_COMP_ID");
				if (lnkCompIdObj != null) {
					Long lnkCompId = Long.valueOf(lnkCompIdObj.toString());
					lnkCompIds.add(lnkCompId);
				}
				Object splIdObj = json.get("SPL_ID");
				if (splIdObj != null) {
					Long splId = Long.valueOf(splIdObj.toString());
					splIds.add(splId);
				}
				Object cstIdObj = json.get("CST_ID");
				if (cstIdObj != null && StringUtils.isNotEmpty(cstIdObj.toString())) {
					Long cstId = Long.valueOf(cstIdObj.toString());
					cstIds.add(cstId);
				}
			}
			List<CapPriArInfoDTO> dataLists = new ArrayList();
			if(CollectionUtils.isNotEmpty(splIds)){
				List<CapPriArInfoDTO> dtoList = this.splCapPrjArInfoService.getCapPrjArInfoDTOByDataIds(splIds, CapPrjArInfoConstant.CODE_MAIN_TYP_CD_4, DateUtils.formatDate(new Date(),DateUtils.YYYY_MM_DD));
				dataLists.addAll(dtoList);
			}
			if(CollectionUtils.isNotEmpty(lnkCompIds)){
				List<CapPriArInfoDTO> dtoList = this.splCapPrjArInfoService.getCapPrjArInfoDTOByDataIds(lnkCompIds, CapPrjArInfoConstant.CODE_MAIN_TYP_CD_3, DateUtils.formatDate(new Date(),DateUtils.YYYY_MM_DD));
				dataLists.addAll(dtoList);
			}
			if(CollectionUtils.isNotEmpty(cstIds)){
				List<CapPriArInfoDTO> dtoList = this.splCapPrjArInfoService.getCapPrjArInfoDTOByDataIds(cstIds, CapPrjArInfoConstant.CODE_MAIN_TYP_CD_1, DateUtils.formatDate(new Date(),DateUtils.YYYY_MM_DD));
				dataLists.addAll(dtoList);
			}
			if(CollectionUtils.isNotEmpty(dataLists)) {
				List<CapPrjArInfoVO> voList = CapPrjArInfoVOTransform.mongoDtoVOList(dataLists);
				ListPageVO<CapPrjArInfoVO> listPage = new ListPageVO<CapPrjArInfoVO>(voList, voList.size());
			}
		}
		return new ListPageVO<CapPrjArInfoVO>();
	}
	
}
